home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-02-09 | 1.8 KB | 78 lines | [TEXT/MPCC] |
- // File: Chaos.c
- //
- // This is a piece of code which can be loaded and called by SimpleApp
- // It draws a simple (but interesting) fractal
-
- #include <Quickdraw.h>
- #include <Windows.h>
- #include <Events.h>
-
- // === Function prototypes
- void DrawFractal (WindowPtr theWindow);
-
-
- // Our main routine can have any calling sequence we want
- // This particular version is defined in SimpleApp.c
- Boolean OurMainRoutine (EventRecord *theEvent, WindowPtr currWindow, QDGlobals *qdAddress)
- {
- Boolean handled = false;
-
- if (theEvent->what == updateEvt) {
- WindowPtr theWindow = (WindowPtr)theEvent->message;
-
- BeginUpdate(theWindow);
- SetPort(theWindow);
-
- DrawFractal(theWindow);
-
- EndUpdate(theWindow);
- handled = true;
- }
-
- return handled; // Did we handle the event?
- }
-
-
- void DrawFractal (WindowPtr theWindow)
- {
- // This routine draws trhe fractal characterized by the population
- // equation x = ax(1-x), for 2.95 ≤ a < 4.00
- // At each value of a, we plot a few hundred values of x
-
- double aMin = 2.95;
- double aMax = 4.00;
- double a, x;
- double deltaA;
- Rect portRect = theWindow->portRect;
- Rect imageRect = (*theWindow->visRgn)->rgnBBox;
- double portWidth = portRect.right - portRect.left;
- short v, h;
-
- // Set up the screen for drawing
- EraseRect(&portRect);
- PenNormal();
-
- deltaA = (aMax - aMin) / (portRect.bottom - portRect.top);
- v = 0;
- for (a = aMin; a < aMax; a += deltaA, v++) {
- register int count;
-
- // Don't bother drawing if this isn't in the visible part of the window
- if ((v < imageRect.top) | (v > imageRect.bottom))
- continue;
-
- // Iterate a few hundred times to give the orbits a chance to get established
- for (count = 1, x = 0.5; count < 100; count++)
- x = a * x * (1.0 - x);
-
- // Now, draw for real
- for (count = 1; count < 500; count++) {
- x = a * x * (1.0 - x);
- h = x * portWidth;
- MoveTo(h, v);
- Line(0, 0);
- }
-
- }
- }
-